package com.yhyvr.api.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by zhangqin on 2016/11/29.
 * 处理微信图片保存操作
 */
public class ImageFilter implements Filter {
        public void destroy() {
        }
        public void doFilter(ServletRequest req, ServletResponse resp,
                             FilterChain chain) throws IOException, ServletException {
            HttpServletRequest httpRequest = (HttpServletRequest) req;
            HttpServletResponse httpResponse = (HttpServletResponse) resp;

            String requestURI = httpRequest.getRequestURI();

            if (requestURI.startsWith("/api")&&(requestURI.endsWith(".jpg"))) {
                httpRequest.getRequestDispatcher (requestURI.replace(".jpg","")). forward(httpRequest, httpResponse);//转发到demo.jsp
                return;
            }else{
                chain.doFilter(req, resp);
            }
        }

        // 项目启动时就已经进行读取
        public void init(FilterConfig config) throws ServletException {
        }
}
